package com.xbfinance.manager.web;

import com.xbfinance.manager.pojo.dto.*;
import com.xbfinance.manager.pojo.po.P2pAccountCash;
import com.xbfinance.manager.service.AdminGetMoneyCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class AdminGetMoneyCheckController {
    @Autowired
    private AdminGetMoneyCheckService adminGetMoneyCheckService;
    @RequestMapping(value="/adminGetMoneyCheck",method= RequestMethod.POST)
    @ResponseBody
    public AdminPageResult<P2pAccountCash> getList(AdminPageParam page){
        AdminPageResult<P2pAccountCash> res=adminGetMoneyCheckService.getList(page);
        return res;
    }
    @RequestMapping(value="/adminDeleteOne/{cid}",method= RequestMethod.DELETE)
    @ResponseBody
    public Map<String,Boolean> deleteOneByCid(@PathVariable("cid") int cid){
        Map<String,Boolean> map = new HashMap<>();
        boolean flag;
        System.out.println(cid);
        int res = adminGetMoneyCheckService.deleteOneByCid(cid);
        System.out.println(res);
        if(res!=0){
            flag=true;
        }else{
            flag=false;
        }
        map.put("flag",flag);
        return map;
    }

    @RequestMapping(value="/adminEditByCid",method= RequestMethod.POST)
    @ResponseBody
    public Map<String,Boolean> adminEditByCid(P2pAccountCash p2p){
        //System.out.println("cid:"+cid);
        Map<String,Boolean> map = new HashMap<>();
        boolean flag;
        System.out.println("p2p:"+p2p);
        int i = adminGetMoneyCheckService.adminEditByCid(p2p);
        if(i!=0){
            flag=true;
        }else{
            flag=false;
        }
        map.put("flag",flag);
        return map;
    }

    @RequestMapping(value="/adminSearch",method= RequestMethod.POST)
    @ResponseBody
    public AdminPageResult<P2pAccountCash> adminSearch(AdminPageParam page,AdminSearch as){
        //System.out.println(as.getQueryCashstatus()+"    "+as.getQueryUserid());
        System.out.println(page.getPage()+"    "+page.getRows());
        System.out.println(as.getQueryUserid());
        AdminPageResult<P2pAccountCash> list = adminGetMoneyCheckService.adminSearch(page,as);
        System.out.println(list);
        return list;
    }

    @RequestMapping(value="/agreeByCid/{cid}/{money}/{fee}",method= RequestMethod.PUT)
    @ResponseBody
    public Map<String,Boolean> agreeByCid(@PathVariable("cid") int cid,@PathVariable("money") double money
                                ,@PathVariable("fee") double fee){
        Map<String,Boolean> map = new HashMap<>();
        boolean flag=false;
        int i = adminGetMoneyCheckService.agreeByCid(cid,money,fee);
        System.out.println(i);
        if(i!=0){
            flag=true;
        }
        map.put("flag",flag);
        return map;
    }

    @RequestMapping(value="/rejectByCid/{cid}",method= RequestMethod.PUT)
    @ResponseBody
    public Map<String,Boolean> rejectByCid(@PathVariable("cid") int cid){
        Map<String,Boolean> map = new HashMap<>();
        boolean flag=false;
        int i = adminGetMoneyCheckService.rejectByCid(cid);
        if(i!=0){
            flag=true;
        }
        map.put("flag",flag);
        return map;
    }

    @RequestMapping(value = "/addDemo",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Boolean> addDemo(P2pAccountCash a){
        Map<String,Boolean> map = new HashMap<>();
        Boolean b = false;
        int i = adminGetMoneyCheckService.addCheck(a);
        if(i!=0){
            b=true;
        }
        map.put("flag",b);
        return map;
    }
    //批量删除
    @RequestMapping(value="/AdminRemovesGetMoneyCheck",method=RequestMethod.POST)
    @ResponseBody
    public Map<String,Boolean> AdminRemovesGetMoneyCheck(@RequestParam("ids[]") List<Integer> list){
        Map<String,Boolean> map = new HashMap<>();
        Boolean b = false;
        int i = adminGetMoneyCheckService.adminRemoves(list);
        if(i!=0){
            b=true;
        }
        map.put("flag",b);
        return map;
    }
}
